package org.itboys.pay.weixin;

import org.itboys.commons.utils.encryption.Digests;
import org.itboys.commons.utils.random.RandomUtils;

/**
 * Created by Administrator on 2016/10/24.
 */
public class JsPaySignTool {

    private String timeStamp;//时间戳
    private String nonceStr;//随机字符串
    private String paySign;//最终得到的签名
    private String appId;
    private String package_;//统一下单接口返回的prepay_id参数值，提交格式如：prepay_id=***
    private String signType="MD5";//签名方式

    /**
     * 实例化时完成加密
     * @param appId
     * @param package_
     */
    public JsPaySignTool(String appId , String package_, String key){
        this.timeStamp = Long.toString(System.currentTimeMillis()/1000);
        this.nonceStr = RandomUtils.getClearRandomStr(16);
        this.appId = appId;
      //  this.package_ = "prepay_id="+package_;
        this.package_ = package_;
        String param = "appId="+this.appId+"&nonceStr="+this.nonceStr+"&package="+this.package_
                +"&signType="+this.signType+"&timeStamp="+this.timeStamp+"&key="+key;
        System.out.println("-------微信统一下单签名生成参数--");
        this.paySign = Digests.md5(param).toUpperCase();
    }

    public JsPaySignTool(String timeStamp, String nonceStr, String paySign, String appId, String package_, String signType) {
        this.timeStamp = timeStamp;
        this.nonceStr = nonceStr;
        this.paySign = paySign;
        this.appId = appId;
        this.package_ = package_;
        this.signType = signType;
    }

    public String getTimeStamp() {
        return timeStamp;
    }
    public void setTimeStamp(String timeStamp) {
        this.timeStamp = timeStamp;
    }
    public String getNonceStr() {
        return nonceStr;
    }
    public void setNonceStr(String nonceStr) {
        this.nonceStr = nonceStr;
    }
    public String getPaySign() {
        return paySign;
    }
    public void setPaySign(String paySign) {
        this.paySign = paySign;
    }
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    public String getPackage_() {
        return package_;
    }
    public void setPackage_(String package_) {
        this.package_ = package_;
    }
    public String getSignType() {
        return signType;
    }
    public void setSignType(String signType) {
        this.signType = signType;
    }

    @Override
    public String toString() {
        return "WeixinPaySignTool [timeStamp=" + timeStamp + ", nonceStr=" + nonceStr + ", paySign=" + paySign
                + ", appId=" + appId + ", package_=" + package_ + ", signType=" + signType + "]";
    }
}
